home *** CD-ROM | disk | FTP | other *** search
- #include <Quickdraw.h>
- #include <WindowMgr.h>
- #include <EventMgr.h>
- #include <ControlMgr.h>
- #include <MenuMgr.h>
- #include <DialogMgr.h>
- #include <FileMgr.h>
- #include <OSUtil.h>
- #include <StdFilePkg.h>
- #include <ToolboxUtil.h>
-
- #define appleID 128 /* menu IDs */
- #define fileID 129
- #define editID 130
-
- #define ErrorAlert 256 /* alert ID */
-
- #define Formats 257 /* dialog ID */
-
- #define chID 256 /* cross hairs cursor ID */
- #define mhID 257 /* move hand cursor ID */
-
- #define apID 256 /* about page ID */
-
- #define OPEN_ITEM 1 /* item id's in menus */
- #define CLOSE_ITEM 2
- #define SAVE_ITEM 3
- #define BURY_ITEM 4
- #define QUIT_ITEM 5
-
- #define UNDO_ITEM 1 /* more item id's. 2 is a gray bar */
- #define CUT_ITEM 3
- #define COPY_ITEM 4
- #define PASTE_ITEM 5
- #define CLEAR_ITEM 6
-
- #define ABOUT_ITEM 1
-
- #define PAINT_SIZE 51840 /* macpaint size in bytes */
- #define PAINT_HIGH 720 /* scanlines high */
- #define PAINT_WIDE 576 /* bits wide */
-
- #define MGR_FMT 3
- #define SUNRAST_FMT 4
- #define TEXT_FMT 5
-
- CursHandle cross_hairs, move_hand;
-
- WindowRecord wRecord; /* global window record */
- WindowPtr myWindow; /* ptr to window */
- MenuHandle myMenus[3]; /* list of menus */
- PicHandle aboutpic; /* PICT used for the About... window */
-
- int quitflag;
- int mpopen; /* flag for macpaint file open */
- int selected; /* flag if a section has been selected */
- int format; /* format of saved bitmap */
-
- int vRef; /* volume reference number for current file */
- Str255 fname; /* general filename variable */
- SFReply reply; /* reply structure from SF routines (package manager) */
-
- int px, py, ww, wh; /* picture x, picture y, window width, window height */
- Rect srect; /* selection rect */
-
- BitMap MPmap;
-
- main()
- {
- InitGraf(&thePort); /* all the macintosh inits */
- InitFonts();
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- MaxApplZone(); /* gets as much memory as possible */
-
- GetWindow(); /* init window(s) */
- GetMenus(); /* init menus */
-
- quitflag = 1; /* application specific inits */
- mpopen = 0;
- selected = 0;
- format = MGR_FMT;
- MPmap.baseAddr = 0L;
- cross_hairs = GetCursor(chID);
- HLock(cross_hairs);
- move_hand = GetCursor(mhID);
- HLock(move_hand);
- aboutpic = GetPicture(apID);
- SetCursor(&arrow);
-
- while(events());
- }
-
- events()
- {
- EventRecord myEvent;
- WindowPtr whichWindow;
- Rect r;
-
- SystemTask(); /* does desk accessory processing */
-
- MagicCursor(); /* cursor updates */
- MagicMenu(); /* menu enable/disable functions */
-
- if (GetNextEvent(everyEvent, &myEvent)) {
- /* the standard event loop */
- switch (myEvent.what) {
- case mouseDown:
- switch (FindWindow(myEvent.where, &whichWindow)) {
- /* rememer, events are in GLOBAL coordinates! */
- case inDesk:
- SysBeep(5); /* in gray area */
- break;
- case inGoAway:
- break;
- case inMenuBar:
- /* do menu events */
- return(DoCommand(MenuSelect(myEvent.where)));
- case inSysWindow:
- /* this belongs to a desk accessory */
- SystemClick(&myEvent, whichWindow);
- break;
- case inDrag: /*in window parts */
- case inGrow:
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- break;
- case inContent:
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- else {
- if (mpopen && myEvent.modifiers & optionKey) {
- TrackHand(myEvent.where);
- }
- else if (mpopen) {
- Select(myEvent.where);
- }
- }
- break;
- default: ;
- } /* end switch FindWindow */
- break;
- case keyDown:
- case autoKey:
- {
- register char theChar;
-
- theChar = myEvent.message & charCodeMask;
- if ((myEvent.modifiers & cmdKey) != 0)
- return( DoCommand(MenuKey(theChar)));
- /* menu equivalents */
- else ; /* don't take typing */
- }
- break;
- case activateEvt:
- break;
- case updateEvt:
- BeginUpdate(myWindow);
- if(mpopen) DispMP();
- EndUpdate(myWindow);
- break;
- default: ;
- } /* end of case myEvent.what */
- } /* if */
- return(quitflag);
- }
-
- GetWindow()
- { /* pull in a window from a resource file and show it in front */
- myWindow = GetNewWindow(256, &wRecord, -1L);
- ShowWindow(myWindow);
- SetPort(myWindow);
- ww = myWindow->portRect.right - myWindow->portRect.left;
- wh = myWindow->portRect.bottom - myWindow->portRect.top;
- }
-
- GetMenus()
- {
- int i;
-
- /* make the apple menu */
- myMenus[0] = NewMenu(appleID, "\P\024");
- AppendMenu(myMenus[0], "\PAbout MPtoMGR...;(-");
- /* about item definition, followed by a gray bar defined by '(-' */
- AddResMenu(myMenus[0], 'DRVR'); /* add in DA's */
- myMenus[1] = GetMenu(fileID); /* get the other menus */
- myMenus[2] = GetMenu(editID);
- for (i=0; i< 3; i++ ) InsertMenu(myMenus[i], 0); /* build bar */
- DrawMenuBar(); /* display the bar */
- }
-
- int DoCommand(mResult)
- long mResult;
- {
- int theItem, temp;
- Str255 name;
- WindowPeek wPtr;
- /* classic menu command routine */
-
- theItem = LoWord(mResult);
- switch (HiWord(mResult)) {
- case appleID:
- if (theItem == 1) {
- DoAboutWindow(); /* about the application */
- }
- else {
- GetItem(myMenus[0], theItem, &name); /* DA open */
- OpenDeskAcc(&name);
- SetPort(myWindow);
- }
- break;
- case fileID: /* file menu */
- switch(theItem) {
- case OPEN_ITEM:
- GetMP();
- break;
- case CLOSE_ITEM:
- CloseMP();
- break;
- case SAVE_ITEM:
- format = Pick_Format();
- SaveBM();
- selected = 0;
- DispMP();
- break;
- case BURY_ITEM:
- SendBehind(myWindow, 0L); /* bury our window */
- break;
- case QUIT_ITEM:
- quitflag = 0;
- break;
- default:
- break;
- }
- break;
- case editID:
- break;
- }
- HiliteMenu(0);
- return(1);
- }
-
- MagicCursor()
- {
- #define OP_LO 1 /* for finding the option key */
- #define OP_HI (1L << 2) /* ditto */
-
- KeyMap mykeymap;
- Point curspos;
- static int outlast = -1;
-
- /* magically sets cursor types. does as little work as possible */
- if (myWindow != FrontWindow() && outlast != 0) {
- /* system window. give them an arrow */
- outlast = 0;
- SetCursor(&arrow);
- }
- else if(myWindow == FrontWindow()) {
- outlast = 1;
- GetMouse(&curspos);
- if (PtInRect(curspos, &(wRecord.port.portRect))) {
- /* in our window */
- GetKeys(&mykeymap);
- if (mykeymap.Key[OP_LO] & (OP_HI)) {
- /* option key set, make the cursor a hand */
- SetCursor(*move_hand);
- }
- else SetCursor(*cross_hairs); /* cross hairs w/o option key */
- }
- else SetCursor(&arrow); /* outside of window, give an arrow */
- }
- }
-
- MagicMenu()
- {
- static int lasttype = 1;
- /* alters the enabled/disable states of menu items as needed */
- /* use a static flag to limit processing when a DA is active */
- if (myWindow != FrontWindow() && lasttype != 0) {
- lasttype = 0;
- /* our window isn't in front, disable our functions */
- DisableItem(myMenus[1], OPEN_ITEM);
- DisableItem(myMenus[1], CLOSE_ITEM);
- DisableItem(myMenus[1], SAVE_ITEM);
- DisableItem(myMenus[1], BURY_ITEM);
- DisableItem(myMenus[1], QUIT_ITEM);
- /* enable editing for DA's*/
- EnableItem(myMenus[2], UNDO_ITEM);
- EnableItem(myMenus[2], CUT_ITEM);
- EnableItem(myMenus[2], COPY_ITEM);
- EnableItem(myMenus[2], PASTE_ITEM);
- EnableItem(myMenus[2], CLEAR_ITEM);
- }
- else if (myWindow == FrontWindow()) {
- lasttype = 1;
- /* disable editing, we don't need it */
- DisableItem(myMenus[2], UNDO_ITEM);
- DisableItem(myMenus[2], CUT_ITEM);
- DisableItem(myMenus[2], COPY_ITEM);
- DisableItem(myMenus[2], PASTE_ITEM);
- DisableItem(myMenus[2], CLEAR_ITEM);
- EnableItem(myMenus[1], BURY_ITEM);
- EnableItem(myMenus[1], QUIT_ITEM);
- if(mpopen) {
- /* enable close and disable open, if something open */
- EnableItem(myMenus[1], CLOSE_ITEM);
- DisableItem(myMenus[1], OPEN_ITEM);
- }
- else {
- /* enable open and disable close, if something closed */
- DisableItem(myMenus[1], CLOSE_ITEM);
- EnableItem(myMenus[1], OPEN_ITEM);
- }
- if(selected) {
- /* only allow a save if something selected */
- EnableItem(myMenus[1], SAVE_ITEM);
- }
- else {
- /* otherwise disable it */
- DisableItem(myMenus[1], SAVE_ITEM);
- }
- }
- }
-
- DoAboutWindow()
- {
- static int first = 1;
- static WindowRecord abRecord;
- static WindowPtr abWindow;
- static Rect prect;
- GrafPort *saveport;
-
- if (first) {
- /* only do this once */
- first = 0;
- abWindow = GetNewWindow(257, &abRecord, -1L);
- /* retrieve window from resource file */
- SetOrigin(0, 0); /* set up coords, and display rect */
- SetRect(&prect, 0, 0, ((*aboutpic)->picFrame).right -
- ((*aboutpic)->picFrame).left, ((*aboutpic)->picFrame).bottom -
- ((*aboutpic)->picFrame).top);
- }
- if (abWindow) { /* the window is valid */
- GetPort(&saveport); /* save old grafport, to be nice */
- SetPort(abWindow); /* make ours current */
- ShowWindow(abWindow); /* display it */
- BringToFront(abWindow);
- DrawPicture(aboutpic, &prect); /* put a picture in it */
- while(!Button()); /* wait for a button press */
- HideWindow(abWindow); /* hide window and restore old port */
- SetPort(saveport);
- }
- }
-
- GetMP()
- {
- /* a routine to read in a macpaint document */
- Ptr srcPtr, s, d; /* pointer for packed data */
- int fd, e;
- register int scanline;
- long fsize;
- unsigned char gbuf[255];
-
- if (MPmap.baseAddr != 0L) DisposPtr(MPmap.baseAddr);
- MPmap.baseAddr = NewPtr((long)PAINT_SIZE);
- srcPtr = NewPtr((long)PAINT_SIZE);
- if (srcPtr == 0L || MPmap.baseAddr == 0L){
- /* can't allocate mem */
- MyError("\PCan't allocate memory!", "\P");
- }
- else {
- if (GetFileName(&fname, &vRef)) {
- if((e = FSOpen(&fname, vRef, &fd)) == 0) {
- fsize = 512L; /* skip 512 byte header */
- FSRead(fd, &fsize, srcPtr);
- GetEOF(fd, &fsize); /* how big is the file? */
- fsize -= 512L; /* subtract header from size */
- FSRead(fd, &fsize, srcPtr); /* read the bulk */
- FSClose(fd); /* close the file */
- s = srcPtr; /* use temporary pointers */
- d = MPmap.baseAddr;
- for(scanline = 0; scanline < 720; scanline++)
- UnpackBits(&s, &d, 72); /* unpack data */
- DisposPtr(srcPtr); /* free source data */
- SetRect(&(MPmap.bounds), 0, 0, PAINT_WIDE, PAINT_HIGH);
- /* macpaint dimensions */
- MPmap.rowBytes = PAINT_WIDE / 8;
- mpopen = 1; /* flag open macpaint */
- SetWTitle(myWindow, &fname); /* title in window */
- px = py = 0; /* align upper corner with window */
- DispMP(); /* show the sucker */
- }
- else {
- sprintf(gbuf, "Error %d opening", e);
- CtoPstr(gbuf);
- MyError(gbuf, &fname);
- }
- }
- }
- }
-
- SaveBM()
- {
- Str255 fn;
- int fd, e;
- long mapsize;
- BitMap savemap;
- char gbuf[255];
-
- SetRect(&(savemap.bounds), 0, 0, srect.right - srect.left,
- srect.bottom - srect.top);
- savemap.rowBytes = (savemap.bounds.right + 7) >> 3;
- savemap.rowBytes += savemap.rowBytes & 0x1;
- mapsize = savemap.rowBytes * savemap.bounds.bottom;
- if ((savemap.baseAddr = NewPtr(mapsize)) == 0L) {
- MyError("\PCan't allocate memory!", "\P");
- }
- else {
- CopyBits(&(MPmap), &savemap, &srect, &(savemap.bounds),
- srcCopy, 0L);
- if (SetFileName(&fn, &vRef)) {
- e = Create(&fn, vRef, 'EDIT', 'TEXT');
- if (e == noErr || e == dupFNErr) {
- if ((e = FSOpen(&fn, vRef, &fd)) == 0) {
- switch(format) {
- case MGR_FMT:
- save_mgr(fd, &savemap);
- break;
- case SUNRAST_FMT:
- save_sunrast(fd, &savemap);
- break;
- case TEXT_FMT:
- save_text(fd, &savemap, &fn);
- break;
- default:
- break;
- }
- GetFPos(fd, &mapsize);
- SetEOF(fd, mapsize);
- FSClose(fd);
- }
- else {
- sprintf(gbuf, "Error %d opening", e);
- CtoPstr(gbuf);
- MyError(gbuf, &fname);
- }
- }
- else {
- sprintf(gbuf, "Error %d creating", e);
- CtoPstr(gbuf);
- MyError(gbuf, &fname);
- }
- }
- DisposPtr(savemap.baseAddr);
- }
- }
-
- save_mgr(fd, map)
- int fd;
- BitMap *map;
- {
- struct mgr_head {
- unsigned char magic[2];
- unsigned char h_wide;
- unsigned char l_wide;
- unsigned char h_high;
- unsigned char l_high;
- } h;
- long size;
-
- h.magic[0] = 'z';
- h.magic[1] = 'z';
- h.h_wide = (((map->bounds.right)>>6)&0x3f) + ' ';
- h.l_wide = ((map->bounds.right)&0x3f) + ' ';
- h.h_high = (((map->bounds.bottom)>>6)&0x3f) + ' ';
- h.l_high = ((map->bounds.bottom)&0x3f) + ' ';
- size = (long)sizeof(struct mgr_head);
- FSWrite(fd, &size, &h);
- size = map->rowBytes * (long)map->bounds.bottom;
- FSWrite(fd, &size, map->baseAddr);
- }
-
- save_sunrast(fd, map)
- int fd;
- BitMap *map;
- {
- struct rast_head {
- long ras_magic;
- long ras_width;
- long ras_height;
- long ras_depth;
- long ras_length;
- long ras_type;
- long ras_maptype;
- long ras_maplength;
- } h;
- long size;
-
- h.ras_magic = 0x59a66a95;
- h.ras_width = map->bounds.right;
- h.ras_height = map->bounds.bottom;
- h.ras_depth = 1L;
- h.ras_length = map->rowBytes * (long)map->bounds.bottom;
- h.ras_type = 1L;
- h.ras_maptype = 0L;
- h.ras_maplength = 0L;
- size = (long)sizeof(struct rast_head);
- FSWrite(fd, &size, &h);
- size = map->rowBytes * (long)map->bounds.bottom;
- FSWrite(fd, &size, map->baseAddr);
- }
-
- save_text(fd, map, fn)
- int fd;
- BitMap *map;
- char *fn;
- {
- char outbuf[512], name[80];
- long size, bytes, i;
- int *bit_word, w_word;
-
- pStrCopy(fn, name);
- PtoCstr(name);
-
- sprintf(outbuf, "DeclareBitmap(%s, %d, %d, %s_bits);\r",
- name, map->bounds.right, map->bounds.bottom, name);
- size = (long)strlen(outbuf);
- FSWrite(fd, &size, outbuf);
- sprintf(outbuf, "/* Format_version=1, Width=%d, Height=%d, Depth=1, Valid_bits_per_item=16\r*/\r",
- map->bounds.right, map->bounds.bottom);
- size = (long)strlen(outbuf);
- FSWrite(fd, &size, outbuf);
- sprintf(outbuf, "short %s_bits[] =\r{\r\t", name);
- size = (long)strlen(outbuf);
- bytes = map->rowBytes * (long)(map->bounds.bottom) / 2L;
- FSWrite(fd, &size, outbuf);
- for(i = 0, w_word = 0, bit_word = (int *)map->baseAddr;
- i < bytes - 1; i++) {
- sprintf(outbuf, "0x%04x, ", *bit_word);
- size = (long)strlen(outbuf);
- FSWrite(fd, &size, outbuf);
- bit_word++;
- w_word = (w_word + 1) & 0x7;
- if (w_word == 0) {
- size = 2L;
- FSWrite(fd, &size, "\r\t");
- }
- }
- sprintf(outbuf, "0x%04x\r}\r", *bit_word);
- size = (long)strlen(outbuf);
- FSWrite(fd, &size, outbuf);
- }
-
- GetFileName(fn, vRef)
- Str255 *fn;
- int *vRef;
- {
- SFTypeList myTypes;
- static Point SFGwhere = {90, 82};
-
- /* asks for a file name. returns true upon valid selection */
- myTypes[0]='PNTG';
- SFGetFile( SFGwhere, "\p", 0L, 1, myTypes, 0L, &reply );
- if (reply.good) {
- pStrCopy(reply.fName, fn);
- *vRef = reply.vRefNum;
- return(1);
- }
- else return(0);
- }
-
- SetFileName(fn, vRef)
- Str255 *fn;
- int *vRef;
- {
- static Point SFPwhere = {90, 82};
-
- SFPutFile(SFPwhere, "\p", fn, 0L, &reply);
- if (reply.good) {
- pStrCopy(reply.fName, fn);
- *vRef = reply.vRefNum;
- return(1);
- }
- else return(0);
- }
-
- CloseMP()
- {
- DisposPtr(MPmap.baseAddr); /* free docment memory */
- MPmap.baseAddr = 0L; /* nil the pointer */
- mpopen = 0; /* clear open flag */
- SetWTitle(myWindow, "\PUntitled"); /* untitle window */
- FillRect(&(myWindow->portRect), white); /* clean window */
- }
-
- pStrCopy( p1, p2 )
- register char *p1, *p2;
- /* copies a pascal string from p1 to p2 */
- {
- register int len;
-
- len = *p2++ = *p1++;
- while (--len>=0) *p2++=*p1++;
- }
-
- MyError( s, f )
- Str255 s, f;
- {
- ParamText(s, f,"\p", "\p");
- Alert(ErrorAlert, 0L);
- }
-
- DispMP()
- {
- Rect drect;
- /* displays a section of a macpaint document starting at px, py which
- * are relative to the macpaint document, 0,0 being the upper left corner.
- * ww and wh are the internal dimensions of the window
- */
- SetRect(&drect, px, py, px + ww, py + wh);
- CopyBits(&(MPmap), &(myWindow->portBits), &drect,
- &(myWindow->portRect), srcCopy, 0L);
- }
-
- Select(where)
- Point where;
- {
- /* allows the selection of a section of a macpaint document.
- * This lets the user sweep out a section of the document, and
- * does auto scrolling if needed, so a section larger than the screen can
- * be selected. If a valid rectangle was selected, it will set the
- * selcted flag and leave the selected rectangle in the global srect,
- * in corrdinates in terms of the document.
- */
- Rect drect, rrect1, rrect2;
- Point corner, cmouse;
- register int dx, dy;
-
- GlobalToLocal(&where); /* get correct coordinate system */
-
- corner.h = where.h;
- corner.v = where.v;
- SetRect(&srect, px + corner.h, py + corner.v,
- px + corner.h, py + corner.v);
- /* set the document selection rectangle */
- SetRect(&rrect1, corner.h, corner.v, corner.h, corner.v);
- /* set the selection rectangle */
- PenMode(patXor); /* use xor drawing for easy animation */
- if (selected) {
- /* something has already been selected, wipe it away */
- SetRect(&drect, px, py, px + ww, py + wh);
- CopyBits(&(MPmap), &(myWindow->portBits), &drect,
- &(myWindow->portRect), srcCopy, 0L);
- }
- FrameRect(&rrect1); /* draw in first rectangle */
- while (StillDown()) { /* loop until selected */
- GetMouse(&cmouse);
- if (cmouse.h > ww || cmouse.h< 0 || cmouse.v > wh || cmouse.v< 0) {
- /* if the mouse is out of bounds, determine amount to scroll */
- dx = dy = 0;
- if (cmouse.h > ww) {
- if (px + ww + 16 > PAINT_WIDE) {
- /* scroll as much as possible, but make sure we only
- * display the painting, and nothing extra
- */
- dx = (PAINT_WIDE - (px + ww));
- if (dx < 0) dx = 0;
- }
- else dx = 16;
- }
- if (cmouse.h < 0) {
- if (px - 16 < 0) {
- dx = px;
- }
- else dx = -16;
- }
- if (cmouse.v > wh) {
- if (py + wh + 16 > PAINT_HIGH) {
- dy = (PAINT_HIGH - (py + wh));
- if (dy < 0) dy = 0;
- }
- else dy = 16;
- }
- if (cmouse.v < 0) {
- if (py - 16 < 0) {
- dy = py;
- }
- else dy = -16;
- }
- px += dx; /* offset corner of display */
- py += dy;
- OffsetRect(&rrect1, -dx, -dy); /* offset select rect */
- corner.h -= dx; /* change corner of selection rect */
- corner.v -= dy;
- if (dx < 0) rrect1.left += dx; /* rect up or down? */
- else rrect1.right += dx;
- if (dy < 0) rrect1.top += dy;
- else rrect1.bottom += dy;
- SetRect(&drect, px, py, px + ww, py + wh);
- CopyBits(&(MPmap), &(myWindow->portBits), &drect,
- &(myWindow->portRect), srcCopy, 0L);
- FrameRect(&rrect1);
- }
- else {
- /* get new select rectangle */
- SetRect(&rrect2, corner.h, corner.v, cmouse.h, cmouse.v);
- /* sort it so that left is really left and top is really top */
- SortRect(&rrect2);
- if(rrect1.bottom != rrect2.bottom ||
- rrect1.left != rrect2.left ||
- rrect1.right != rrect2.right ||
- rrect1.top != rrect2.top) {
- /* if the rects differ, draw the new, and erase the old */
- FrameRect(&rrect2);
- FrameRect(&rrect1);
- rrect1 = rrect2;
- }
- }
- } /* end while(StillDown()); */
-
- if (cmouse.h < 0) cmouse.h = 0;
- if (cmouse.h > ww) cmouse.h = ww;
- if (cmouse.v < 0) cmouse.v = 0;
- if (cmouse.v > wh) cmouse.v = wh;
-
- srect.right = px + cmouse.h;
- srect.bottom = py + cmouse.v;
- SortRect(&srect); /* sort the selection rect */
- if (srect.top != srect.bottom && srect.left != srect.right) {
- /* a valid selection was made */
- selected = 1;
- }
- else {
- /* redraw the screen */
- SetRect(&drect, px, py, px + ww, py + wh);
- CopyBits(&(MPmap), &(myWindow->portBits), &drect,
- &(myWindow->portRect), srcCopy, 0L);
- }
- }
-
- SortRect(r)
- register Rect *r;
- {
- /* sorts the rectangle so left is truly left of right, and
- * top is truly above the bottom. The Macintosh rect routines
- * puke if they don't get the "correct" coords.
- */
- register int bucket;
-
- if (r->left > r->right) {
- bucket = r->left;
- r->left = r->right;
- r->right = bucket;
- }
- if (r->top > r->bottom) {
- bucket = r->top;
- r->top = r->bottom;
- r->bottom = bucket;
- }
- }
-
- TrackHand(where)
- Point where;
- {
- /* this tracks the hand cursor to allow the user to scroll around the
- * document fairly swiftly.
- */
- Rect drect;
- Point cmouse;
- register int x, y, xlim, ylim;
-
- xlim = PAINT_WIDE - ww; /* screen limits */
- ylim = PAINT_HIGH - wh;
- x = px;
- y = py;
- GlobalToLocal(&where);
- selected = 0; /* unselect rectangle */
- HideCursor(); /* get rid of the hand for a better appearance */
- while(StillDown()) {
- GetMouse(&cmouse); /* current mouse */
- x += (where.h - cmouse.h); /* scroll the difference in coords */
- y += (where.v - cmouse.v);
- where = cmouse;
- /* make it in bounds */
- if (x < 0) x = 0;
- if (x > xlim) x = xlim;
- if (y < 0) y = 0;
- if (y > ylim) y = ylim;
- SetRect(&drect, x, y, x + ww, y + wh); /* new subrect to display */
- CopyBits(&(MPmap), &(myWindow->portBits), &drect,
- &(myWindow->portRect), srcCopy, 0L);
- }
- px = x; /* final upper left corner */
- py = y;
- DispMP(); /* draw it for good measure */
- ShowCursor(); /* return the cursor */
- }
-
- Pick_Format()
- {
- DialogPtr myDialog;
- GrafPort *saveport;
- int itemhit, itemtype, fmt;
- Handle theitem;
- Rect r;
-
- GetPort(&saveport);
- myDialog = GetNewDialog(Formats, 0L, -1L);
- SetPort(myDialog);
- ShowWindow(myDialog);
- GetDItem(myDialog, format, &itemtype, &theitem, &r);
- SetCtlValue((ControlHandle)theitem, 1);
- DrawDialog(myDialog);
- fmt = format;
- GetDItem(myDialog, fmt, &itemtype, &theitem, &r);
- SetCtlValue((ControlHandle)theitem, 1);
- do {
- ModalDialog(0L, &itemhit);
- if (itemhit != fmt && (itemhit >= MGR_FMT && itemhit <= TEXT_FMT)){
- GetDItem(myDialog, itemhit, &itemtype, &theitem, &r);
- SetCtlValue((ControlHandle)theitem, 1);
- GetDItem(myDialog, fmt, &itemtype, &theitem, &r);
- SetCtlValue((ControlHandle)theitem, 0);
- fmt = itemhit;
- }
- } while (itemhit != 1);
- DisposDialog(myDialog);
- SetPort(saveport);
- return(fmt);
- }
-
- strlen(s)
- register char *s;
- {
- char *s0 = s;
-
- while (*s++);
- return (s-s0-1);
- }
-